#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>

char getFirst();

int main() {
    int min = 1;
    int max = 100;
    printf("请你选择一个1-100中的整数.\n");
    int select;
    int mid = 0;
    do {
        if (mid + 1 == max) {
            min = max;
        }
        mid = (max + min) / 2;
        printf("你选择的数是：%d,n->不是,y->是", mid);
        while (true) {
            char choice = getFirst();
            if (choice == 'y') {
                max = min;
                printf("bye!\n");
                goto l;
            } else if (choice == 'n') {
                printf("这个数大于%d还是小于%d?输入1选择大于输入2选择小于：", mid, mid);
                break;
            } else {
                printf("请选择:n,y!\n");
                continue;
            }
        }
        scanf("%d", &select);
        if (select == 1) {
            min = mid;
        } else if (select == 2) {
            max = mid;
        } else {
            printf("只能选择1和2");
        }
        l:;
    } while (max != min);
    return 0;
}

char getFirst() {
    char c1;
    char c;
    int sum = 0;
    while ((c = getchar()) != '\n') {
        if (c)
            if (sum == 0) {
                c1 = c;
                sum++;
            }

    }
    return c1;
}